package cn.techwis.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@NoArgsConstructor
@Data
@Builder
@AllArgsConstructor
public class PayOrderVO {

    /**
     * 应用ID
     */
    @NotBlank(message = "应用ID不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    private String appid;

    /**
     * 直连商户号
     */
    @NotBlank(message = "商户号不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    private String mchid;


    /**
     * 商品描述
     */
    @NotBlank(message = "商品描述不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    private String description;

    /**
     * 商户订单号
     */
    @NotBlank(message = "商户订单号不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    private String out_trade_no;

    /**
     * 交易结束时间
     */
    private String time_expire;

    /**
     * 附加数据
     */
    private String attach;
    /**
     * 回调地址
     */
    @NotBlank(message = "通知地址不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    private String notify_url;

    /**
     * 订单优惠标记 WXG
     */
    private String goods_tag;

    /**
     * 金额
     */
    @NotNull(message = "总金额不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
    @Valid
    private AmountVO amount;

    /**
     * 优惠功能
     */
    private DetailVO detail;

    /**
     * 支付者
     */
    @NotNull(message = "支付者不能为空", groups = {JsapiPay.class})
    @Valid
    private PayerVO payer;

    /**
     * + 场景信息
     */
    @NotNull(message = "场景信息不能为空", groups = {H5Pay.class})
    @Valid
    private SceneInfoVO scene_info;

    @NoArgsConstructor
    @Data
    @Builder
    @AllArgsConstructor
    public static class AmountVO {
        /**
         * total : 100
         * currency : CNY
         */
        /**
         * 金额 单位分
         */
        @NotNull(message = "金额不能为空", groups = {JsapiPay.class, AppPay.class, H5Pay.class, NativePay.class})
        private Integer total;
        /**
         * 货币类型 CNY
         */
        private String currency = "CNY";
    }

    @NoArgsConstructor
    @Data
    @Builder
    @AllArgsConstructor
    public static class PayerVO {
        /**
         * openid : 用户标识 用户在直连商户appid下的唯一标识。
         */
        @NotBlank(message = "openid不能为空")
        private String openid;
    }

    @NoArgsConstructor
    @Data
    @Builder
    @AllArgsConstructor
    public static class DetailVO {
        /**
         * invoice_id : wx123
         * goods_detail : [{"goods_name":"iPhoneX 256G","wechatpay_goods_id":"1001","quantity":1,"merchant_goods_id":"商品编码","unit_price":828800},{"goods_name":"iPhoneX 256G","wechatpay_goods_id":"1001","quantity":1,"merchant_goods_id":"商品编码","unit_price":828800}]
         * cost_price : 608800
         */

        /**
         * 商家小票ID
         */
        private String invoice_id;
        /**
         * 单品列表信息
         * 条目个数限制：【1，6000】
         */
        private List<GoodsDetailVO> goods_detail;
        /**
         * 订单原价
         */
        private int cost_price;

        @NoArgsConstructor
        @Data
        @Builder
        @AllArgsConstructor
        public static class GoodsDetailVO {
            /**
             * goods_name : iPhoneX 256G
             * wechatpay_goods_id : 1001
             * quantity : 1
             * merchant_goods_id : 商品编码
             * unit_price : 828800
             */

            /**
             * 商品名称
             */
            private String goods_name;
            /**
             * 微信侧商品编码
             */
            private String wechatpay_goods_id;
            /**
             * ]
             * 商品数量
             */
            private int quantity;
            /**
             * 商户侧商品编码
             */
            private String merchant_goods_id;
            /**
             * 商品单价
             */
            private int unit_price;
        }
    }

    @NoArgsConstructor
    @Data
    @Builder
    @AllArgsConstructor
    public static class SceneInfoVO {
        /**
         * store_info : {"address":"广东省深圳市南山区科技中一道10000号","area_code":"440305","name":"腾讯大厦分店","id":"0001"}
         * device_id : 013467007045764
         * payer_client_ip : 14.23.150.211
         */

        /**
         * + 商户门店信息
         */
        private StoreInfoVO store_info;
        /**
         * 商户端设备号
         */
        private String device_id;
        /**
         * 用户终端 IP
         */
        @NotBlank(message = "用户终端IP不能为空", groups = {H5Pay.class})
        private String payer_client_ip;

        private H5info h5info;

        @NoArgsConstructor
        @Data
        @Builder
        @AllArgsConstructor
        public static class H5info {

            /**
             * 场景类型 示例值：iOS, Android, Wap
             */
            @NotBlank(message = "场景类型不能为空", groups = {H5Pay.class})
            private String type;
            /**
             * 应用名称
             */
            private String app_name;
            /**
             * 网站URL
             */
            private String app_url;
            /**
             * iOS平台BundleID
             */
            private String bundle_id;
            /**
             * Android平台PackageName
             */
            private String package_name;

        }

        @NoArgsConstructor
        @Data
        @Builder
        @AllArgsConstructor
        public static class StoreInfoVO {
            /**
             * address : 广东省深圳市南山区科技中一道10000号
             * area_code : 440305
             * name : 腾讯大厦分店
             * id : 0001
             */

            /**
             * 详细地址
             */
            private String address;
            /**
             * 地区编码
             */
            private String area_code;
            /**
             * 门店名称
             */
            private String name;
            /**
             * 门店编号
             */
            private String id;
        }
    }


    public @interface JsapiPay {
    }


    public @interface AppPay {
    }


    public @interface H5Pay {
    }

    public @interface NativePay {
    }

}
